package com.example.demo1.wyy.service.impl;


import com.example.demo1.wyy.dao.PlantMapper;
import com.example.demo1.wyy.model.Plant;
import com.example.demo1.wyy.model.vo.PlantAddVo;
import com.example.demo1.wyy.service.MPlantService;
import com.example.demo1.wyy.util.Result;
import com.example.demo1.wyy.util.ResultVO;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Lx on 2018/6/27.
 */
@Service
public class MPlantServiceImpl implements MPlantService {


    @Autowired
    private PlantMapper plantMapper;

    public List<Plant> queryAll(){
    /*    Integer id = 1;
        return plantMapper.queryById(id);*/
        return plantMapper.queryAll();
    }
    /*
    @Override
    public Result<PlantAddVo> addPlant(PlantAddVo plantAddVo) {
        //验证数据是否合法
        Result<PlantAddVo> plantAddVoResult = validData(plantAddVo);
        if (!plantAddVoResult.getStatus()){
            return ResultVO.error(plantAddVoResult.getCode(),plantAddVoResult.getMsg());
        }
        Plant plant = new Plant();
        BeanUtils.copyProperties(plantAddVo,plant);
        plantMapper.savePlant(plant);
        return ResultVO.success(plant);
    }

    private Result<PlantAddVo> validData(PlantAddVo plantAddVo){
        //验证工厂编码是否唯一，传入工厂编码到数据库中查询是否存在工厂编码
        List<Plant> plantList = plantMapper.findByCode(plantAddVo.getCode());
        if (!CollectionUtils.isEmpty(plantList)){
            return ResultVO.error(500,"工厂编码已存在！");
        }
        //验证法人编码是否存在
        LegalPerson legalPerson = plantMapper.findOne(plantAddVo.getLegalPersonId());
        if (legalPerson==null){
            return ResultVO.error(500,"法人信息不存在！");
        }
        return ResultVO.success(plantAddVo);
    }
*/

}
